import jwt

from Webmaster.settings import SECRET_KEY


class Jwt:
    def gen_jwt(self,user):
        payload={
            'id':user.id,
            'user':user.name
        }
        token=jwt.encode(payload,SECRET_KEY)
        return token

    def valid_jwt(self,token):

        try:
            payload=jwt.decode(token,SECRET_KEY,algorithms='HS256')
            # print(payload)
        except Exception as e:
            print(e)
            return {}
        return payload
